package com.vortex.cloud.sample;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;


/**
 * @author 王林
 * @version 1.0
 * @date 2021-10-13 周三
 * @time 11:11
 * @description
 */
@EnableCaching
@EnableDiscoveryClient
@ServletComponentScan(basePackages = "com.vortex")
@SpringBootApplication(scanBasePackages = "com.vortex")
public class WebBootApplication {
    private static final Logger logger = LoggerFactory.getLogger(WebBootApplication.class);
    private static final String SWAGGER_PATH = "/swagger-ui.html";

    public static void main(String[] args) throws UnknownHostException {
//        ApplicationContext ctx = SpringApplication.run(WebBootApplication.class, args);
//        String[] activeProfiles = ctx.getEnvironment().getActiveProfiles();
//        for (String profile : activeProfiles) {
//            logger.error("Spring Boot 使用profile为:{}", profile);
//        }
        ConfigurableApplicationContext application = SpringApplication.run(WebBootApplication.class, args);
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        if (StringUtils.isEmpty(path)) {
            path = "";
        }
        logger.info("~~~~~~~~~~~~~~~~~~~~~~~~~~系统启动成功~~~~~~~~~~~~~~~~~~~~~~~~~~");
        logger.info("------------------------------------------------------\n\t" +
                "Application  is running! Access URLs:\n\t" +
                "Local访问网址: \t\thttp://localhost:" + port + path + SWAGGER_PATH + "\n\t" +
//                "External访问网址: \thttp://" + ip + ":" + port + path + "\n\t" +
                "----------------------------------------------------------");
    }
}
